#include "gtlSystem.h"
#include "gtlStrings.h"

#ifdef GTL_OS_WINDOWS
#include "gtlWindowsIncludes.h"
#endif

namespace GTL
{
	namespace System
	{

		eastl::string GetComputerName()
		{
#ifdef GTL_OS_WINDOWS
			char buf[MAX_COMPUTERNAME_LENGTH + 1] = {0};
			DWORD size = sizeof(buf);
			::GetComputerNameA(buf, &size);
			return buf;
#endif
		}

		eastl::string GetClipboardUTF8Text()
		{
			eastl::string ret;
			OpenClipboard(0);
			for (int format = EnumClipboardFormats(0); format; format = EnumClipboardFormats(format))
			{
				/// Holy mother of fuck, wtf is this shit
				if (format == CF_UNICODETEXT)
				{
					HANDLE handle = GetClipboardData(format);
					const wchar_t* text = (const wchar_t*)GlobalLock(handle);
					ret = GTL::Strings::UTF8::WideCharToUTF8(text);
					GlobalUnlock(handle);
					break;
				} 
				else if (format == CF_OEMTEXT || format == CF_TEXT)
				{
					HANDLE handle = GetClipboardData(CF_TEXT);
					const char* text = (const char*)GlobalLock(handle);
					ret = text;
					GlobalUnlock(handle);
					break;
				}
			}
			CloseClipboard();
			return ret;
		}
	}
}